'''
    这份文件主要用于爬取微博相册中的下载地址
'''

import requests
import json


headers = {
    'Cookie':'SINAGLOBAL=618919066387.7864.1624346401618; UOR=ilive.lenovo.com.cn,s.weibo.com,www.baidu.com; ULV=1715763314391:65:1:1:1143349720519.5286.1715763314389:1712387997847; ALF=1718355336; SUB=_2A25LQAjYDeRhGeBM7FMY9y_MzDqIHXVoPAQQrDV8PUJbkNANLUqtkW1NRNyWoXjoHBcQOlhuypndlHGIPpo7L3Ii; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WhTNAlv6EWJAXoS..AAr1Kh5JpX5KzhUgL.FoqES024S027S0q2dJLoI0qLxKBLB.zL1KqLxK-L12qLB-2LxKqL1KnLB-qLxKqL1-eL1h.LxKML1hzLBo.LxK-L1K2L1hqt; XSRF-TOKEN=kx5jb_9t1vvvNGwwNr6Kr188; WBPSESS=03Rwz19Z2C7dvXKIo40JJUonpHzzhP1JQuWdfXlDkW7M72rIIe3Dsnpc0CcHRu13qK4emuJBNXOZeSpXXJHkriVyy1YKZEonDTSo-rjRhqg4xNRJVtuC4E3udilWgTTC1Uf8Urb2BMmsXPp9XVJeNg==',
    'Referer':'https://weibo.com/u/7744301004?tabtype=album',
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0'
}

flag = 0
def download(url):
    resp = requests.get(url,headers=headers)
    json_data = resp.json()
    since_id = json_data['data']['since_id']
    if json_data['data']['since_id']:
        next_url = 'https://weibo.com/ajax/profile/getImageWall?uid=7744301004&sinceid={}'
        new_url = next_url.format(since_id)
        # print(new_url)
        with open('爬取文件/url.csv',mode='a') as f:
            f.write(new_url+'\n')
            print('写入成功')
        download(new_url)
def main():
    url = 'https://weibo.com/ajax/profile/getImageWall?uid=7744301004&sinceid=0&has_album=true'
    download(url)

if __name__ == '__main__':
    main()